//发送验证码
var c=require('../common.js');
var config=require('../config.js');
function sendcode(phone,that,typeinfo){
  var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
  if (!phoneReg.test(phone)) {
    wx.showToast({
      title: '手机号码有误',
      image: '/images/closered.png'
    })
    return false;
  }
 
  c.ajax(
    config.hostapi + "/PhoneCode/getPhoneCode",
    {
      phone: phone, type: typeinfo, utype: 'user'
    },
    res => {
      if (res.data.code == 100) {
        wx.showToast({
          title: res.data.info,
          image: '/images/dui.png'
        })
        var timer = null;
        that.setData({
          flag: 60
        })
        timer = setInterval(() => {
          if (that.data.flag == 0) {
            clearInterval(timer)
            that.setData({
              flag: 0
            })
          }
          else {
            that.setData({
              flag: that.data.flag - 1
            })
          }

        }, 1000)
      } else {
        wx.showToast({
          title: res.data.info,
          image: '/images/closered.png'
        })
      }
    }
  )

  
}
module.exports={
  sendcode: sendcode,
}